package com.opages.netty.demo.netty.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * byte 转成 long
 * @author daizhong.liu
 * @create 2021-12-14 15:58
 **/
public class ByteToLongDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.err.println("ByteToLongDecoder调用");
        System.err.println("--->>> "+in.readableBytes());
        if(in.readableBytes() >= 8) {
            out.add(in.readLong());
        }
    }
}
